layui.config({
    base: 'assets/layuiadmin/' //静态资源所在路径
}).extend({
    index: 'lib/index' //主入口模块
}).use(['index', 'form'], function(){
    var $ = layui.$, form = layui.form;

    var id = $('#id').val();
    var data = {'id': id};
    post('channel/toEdit', data,false,function (data) {
        var channelUser = data.channelUser;
        if(channelUser.type == 1){  //主播渠道
            $('input[name="type"]').eq(0).attr('checked', 'checked');
            $('.type2').hide();
            $('.type2 input').removeAttr('lay-verify');
            $('.type1').show();
            $('.type1 input').attr('lay-verify', 'required');
        }else if(channelUser.type == 2){    //cps渠道
            $('input[name="type"]').eq(1).attr('checked', 'checked');
            $('.type1').hide();
            $('.type1 input').removeAttr('lay-verify');
            $('.type2').show();
            $('.type2 input').attr('lay-verify', 'required');
        }
        $('input[name="type"]').attr('disabled', 'disabled');
        form.render('radio');

        $('#code').val(channelUser.code);
        $('#username').val(channelUser.username);
        $('#realname').val(channelUser.realname);
        $('#idNo').val(channelUser.idNo);
        $('#linkMail').val(channelUser.linkMail);
        $('#linkQq').val(channelUser.linkQq);
        $('#linkWx').val(channelUser.linkWx);
        $('#linkPhone').val(channelUser.linkPhone);
        $('#linkAlipayName').val(channelUser.linkAlipayName);
        $('#linkAlipayNo').val(channelUser.linkAlipayNo);
        $('#first_invite_recharge_rate').val(channelUser.first_invite_recharge_rate);
        $('#first_invite_rate').val(channelUser.first_invite_rate);
        $('#second_invite_recharge_rate').val(channelUser.second_invite_recharge_rate);
        $('#second_invite_rate').val(channelUser.second_invite_rate);
        $('#first_invite_vip_rate').val(channelUser.first_invite_vip_rate);
        $('#first_invite_user_rate').val(channelUser.first_invite_user_rate);
    });

    $('#data-submit').on('click', function () {
        var realname = $('#realname').val();
        var idNo = $('#idNo').val();
        var linkMail = $('#linkMail').val();
        var linkQq = $('#linkQq').val();
        var linkWx = $('#linkWx').val();
        var linkPhone = $('#linkPhone').val();
        var linkAlipayName = $('#linkAlipayName').val();
        var linkAlipayNo = $('#linkAlipayNo').val();
        var data = {'id': id, 'realname': realname, 'idNo': idNo, 'linkMail': linkMail, 'linkQq': linkQq, 'linkWx': linkWx,
            'linkPhone': linkPhone, 'linkAlipayName': linkAlipayName, 'linkAlipayNo': linkAlipayNo};
        post('channel/edit', data, false, function (resultData) {
            layer.msg("更新成功");
        });
    });

});